#include <bits/stdc++.h>
using namespace std;
const int N = 300;
char s[N][N];
int n, m;

int main() {
#ifdef LOCAL
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif
    int T;
    cin >> T;
    while (T--) {
        cin >> n >> m;
        for (int i = 1; i <= n; i++) {
            scanf("%s", s[i] + 1);
        }
        bool flag = 1;
        while (false) {
            
        }
        for (int i = 1; i <= n - 1; i++) {
            for (int j = 1; j <= m - 1; j++) {
                int cnt = 0;
                for (int x = 0; x <= 1; x++) {
                    for (int y = 0; y <= 1; y++) {
                        if (s[i + x][j + y] == '1') {
                            cnt++;
                        }
                    }
                }
                if (cnt == 3) {
                    flag = 0;
                    break;
                }
            }
            if (!flag) break;
        }

        puts(flag ? "YES" : "NO");
    }
}